using FubuMVC.Core.Behaviors;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Runtime;
using FubuMVC.Spark.Rendering;
using complex.Controllers;

namespace complex.Behaviors
{
    public class SparkHtmlTagOutput
        : OutputNode<SparkHtmlTagRenderer>
    {
    }

    public class SparkHtmlTagRenderer 
        : IActionBehavior
    {
        private readonly IOutputWriter outputWriter;
        private readonly NestedOutput nestedOutput;
        private readonly IFubuRequest request;

        public SparkHtmlTagRenderer(IOutputWriter outputWriter, NestedOutput nestedOutput, IFubuRequest request)
        {
            this.outputWriter = outputWriter;
            this.nestedOutput = nestedOutput;
            this.request = request;
        }

        public void Invoke()
        {
            var tag = request.Get<SparkHtmlTag>();
            outputWriter.WriteHtml(tag);
        }

        public void InvokePartial()
        {
            var tag = request.Get<SparkHtmlTag>();
            nestedOutput.Writer.Write(tag);
        }
    }
}